﻿#ifndef JFLYRECORD_H
#define JFLYRECORD_H

#include "jfileparse_global.h"
#include <QStringList>
#include "jsqldatamgr.h"

// - class JFlyRecord -

class JFlyRecordPrivate;
class QFile;

class JFILEPARSE_EXPORT JFlyRecord
{
public:
    bool parseFileName(const QString &filePath, QString &JX);
    bool parseFileName(const QString &filePath, JFileNameInfo &info);
    bool parseFileHeader(const QString &filePath, QStringList &symbols);
    bool parseFileBaseInfo(const QString &filePath, JFileBaseInfo &info);

    bool parseFile(const QString &filePath, const QList<stSignalSiftInfo> &sifts,
                   bool isGlobalMode, bool isIgnoreSift);
    bool parseFile(const QStringList &filePaths, const QList<stSignalSiftInfo> &sifts,
                   bool isGlobalMode, bool isIgnoreSift);

    /**
     * @brief classifyFile
     * @param filePaths
     * @param newFilePaths
     * @return
     */
    static bool classifyFile(const QStringList &filePaths, QList<QStringList> &classifiedFilePaths);

    static QString fileNamePattern();
    static bool exactMatchFileName(const QString &fileName);

    /**
     * @brief readSignalMHSection
     * @param info
     * @param machSection
     * @param heightSection
     * @return
     */
    bool readSignalMHSection(const JFileNameInfo &info,
                             QString &machSection,
                             QString &heightSection) const;

    /**
     * @brief readSignalMHSection
     * @param tableName
     * @param machSection
     * @param heightSection
     * @return
     */
    bool readSignalMHSection(const QString &tableName,
                             QString &machSection,
                             QString &heightSection) const;

    /**
     * @brief readSignalMHName
     * @param info
     * @param machSection
     * @param heightSection
     * @param machName
     * @param heightName
     * @return
     */
    bool readSignalMHName(const JFileNameInfo &info,
                          const QString &machSection,
                          const QString &heightSection,
                          QString &machName,
                          QString &heightName) const;

    /**
     * @brief readSignalMHName
     * @param tableName
     * @param machSection
     * @param heightSection
     * @param machName
     * @param heightName
     * @return
     */
    bool readSignalMHName(const QString &tableName,
                          const QString &machSection,
                          const QString &heightSection,
                          QString &machName,
                          QString &heightName) const;

    /**
     * @brief samplingRecordData
     * @param suffix
     * @param interval
     * @return
     */
    bool samplingRecordData(const QString &suffix,
                            int interval);

private:
    bool parseRecords(const QString &filePath,
                      const QString &tableName, const QStringList &oldSymbols,
                      const QStringList &validSymbols,
                      const QList<stSignalInfo> &signalInfos,
                      bool ignoreSift, bool isEmptyTable);

private:
    JFlyRecord();
    ~JFlyRecord();

private:
    J_DECLARE_PRIVATE(JFlyRecord)
    J_DECLARE_SINGLE_INSTANCE(JFlyRecord)
};

//TEST

#if 1

// - class JFlyRecordGenerater -

class JFlyRecordGeneraterPrivate;

class JFILEPARSE_EXPORT JFlyRecordGenerater
{
public:
    bool generateFlyRecordFile(const QString &filePath, const QStringList &symbols, long rowCount);

private:
    JFlyRecordGenerater();
    ~JFlyRecordGenerater();

private:
    J_DECLARE_PRIVATE(JFlyRecordGenerater)
    J_DECLARE_SINGLE_INSTANCE(JFlyRecordGenerater)
};

#endif

#endif // JFLYRECORD_H
